Q:
When I use the screenMenuBar property from Q&A 1003,
submenus in my Swing application do not update if I add or
remove JMenuItems to them.
A:
This is a known problem with the current screenMenuBar implementation,
and does not occur when using AWT, or using Swing without
the screenMenuBar property set. The only current workaround
is to remove and rebuild the submenu so the changed contents
are forced to repaint in the Mac OS Screen MenuBar. Listing
1 shows how this might be done.
// Workaround: Get all components of the subMenu and rebuild/replace it
// Call this code whenever adding or removing a Component of any kind
// (including JSeparators etc.) to a submenu
Component[] subMenuItems = subMenu.getMenuComponents();
topMenu.remove(subMenu);
subMenu = new JMenu("Open Recent");
for (int i=0; i < subMenuItems.length; i++) {
subMenu.add(subMenuItems[i]);
}
topMenu.add(subMenu);
|
Listing 1. (Workaround) Removal of JMenuItem s from submenus.
|
[Jul 12 2002]
|